# 1，调用自身
# 2. 有结束条件 -> while 循环


def func_1(x):
    print(x)
    func_1(x - 1)


def func_2(x):
    if x > 0:
        print(x)
        func_2(x + 1)


def func_3(x):
    if x > 0:
        print(x)
        func_3(x - 1)


def func_4(x):
    if x > 0:
        func_4(x - 1)
        print(x)


def find_json(_json, target_key, result_list=None):
    """
    解析一个 json 对象（字典或者列表），要求获取到指定 key 的值
    :param _json: 解析目标的json对象，list、dict
    :param target_key: 需要获取的目标key的值
    :param result_list: 统一存放获取的结果
    :return:
    """
    if result_list is None:
        result_list = []
    if isinstance(_json, dict):
        if target_key in _json.keys():
            result_list.append(_json[target_key])
        for value in _json.values():
            find_json(value, target_key, result_list)
    elif isinstance(_json, list):
        for inner_json in _json:
            find_json(inner_json, target_key, result_list)
    return result_list


if __name__ == "__main__":
    json_a = {
        "key1": "value1",
        "key2": "value2",
        "key3": {
            "key1": "value3",
            "key4": "value4"
        },
        "key5": [
            {
                "key1": "value5",
                "key6": "value6"
            }, {
                "key1": []
            }
        ]
    }

    result = find_json(json_a, "key1")
    print(result)
